package com.h3bpm.web.utils;

import org.apache.commons.lang3.time.DateFormatUtils;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class QjcUtils {



    /**
     *  对合同锚点参数 转换
     * @param obj
     * @return
     */
    public static Object contractParamFilter(Object obj){

        if (obj == null) {
            return obj;
        }

        if (obj instanceof Date) {
            obj = DateFormatUtils.format((Date) obj,"yyyy-MM-dd");
        }


        return  obj;

    }

    /**
      * 获取指定url中的某个参数
      * @param url
      * @param name
      * @return
      */
    public static String getParamByUrl(String url, String name) {

        if (url.indexOf("?") == -1) {
            return null;
        }

        Pattern pattern = Pattern.compile("(^|&)" + name + "=([^&]*)(&|$)" );
        url = url.substring(url.indexOf("?")+1);
        Matcher m = pattern.matcher(url);
        if (m.find()) {
            return m.group(2) ;
        } else {
            return null;
        }
    }

    /**
     *
     * @param obj 数字
     * @return
     */
    public static int getInt(Object obj){
        int zore = 0;
        if (obj == null) {
            return zore;
        }
        if ("".equals(obj)) {
            return zore;
        }


        return Integer.valueOf(String.valueOf(obj));

    }

    public static int getInt(Integer integer){
        if (integer == null) {
            return 0;
        }
        return integer;
    }



}
